package p270jp.pxv.android.activity;

import android.content.Context;
import android.content.Intent;
import android.util.Pair;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import p014ae.AbstractActivityC0175w0;
import p014ae.C0135p4;
import p014ae.C0185y;
import p045be.IllustPagerAdapter;
import p071cd.Functions;
import p134ei.AnalyticsScreenName;
import p165fo.C3114c;
import p184gi.ImpDetailEvent;
import p187gl.PixivRequest;
import p216hn.DefaultConstructorMarker;
import p270jp.pxv.android.event.IllustDetailPageChangeEvent;
import p270jp.pxv.android.legacy.analytics.firebase.model.ComponentVia;
import p270jp.pxv.android.legacy.model.GoogleNg;
import p270jp.pxv.android.legacy.model.PixivIllust;
import p270jp.pxv.android.model.AddIllustsFromIllustViewPagerCallback;
import p307l9.EdgeTreatment;
import p325m0.MutabilityOwnership;
import p347mm.ItemPagerListManager;
import p374nm.C5410r;
import p374nm.C5417y;
import p645yc.AndroidSchedulers;

/* compiled from: IllustDetailPagerActivity.kt */
/* renamed from: jp.pxv.android.activity.IllustDetailPagerActivity */
/* loaded from: classes2.dex */
public final class IllustDetailPagerActivity extends AbstractActivityC0175w0 {

    /* renamed from: r0 */
    public static final C4012a f18371r0 = new C4012a(null);

    /* renamed from: m0 */
    public WeakReference<AddIllustsFromIllustViewPagerCallback> f18372m0;

    /* renamed from: n0 */
    public String f18373n0;

    /* renamed from: o0 */
    public boolean f18374o0;

    /* renamed from: p0 */
    public ComponentVia f18375p0;

    /* renamed from: q0 */
    public AnalyticsScreenName f18376q0;

    /* compiled from: IllustDetailPagerActivity.kt */
    /* renamed from: jp.pxv.android.activity.IllustDetailPagerActivity$a */
    /* loaded from: classes2.dex */
    public static final class C4012a {
        public C4012a(DefaultConstructorMarker eVar) {
        }

        /* renamed from: a */
        public final Intent m4821a(Context context, List<? extends PixivIllust> list, int i, AddIllustsFromIllustViewPagerCallback addIllustsFromIllustViewPagerCallback, String str, ComponentVia componentVia, AnalyticsScreenName cVar) {
            MutabilityOwnership.m3745m(context, "context");
            MutabilityOwnership.m3745m(list, "illusts");
            EdgeTreatment.m3910h(i >= 0);
            ArrayList arrayList = new ArrayList(list);
            Intent intent = new Intent(context, IllustDetailPagerActivity.class);
            String uuid = UUID.randomUUID().toString();
            MutabilityOwnership.m3746l(uuid, "randomUUID().toString()");
            ItemPagerListManager kVar = ItemPagerListManager.f23059b;
            Objects.requireNonNull(kVar);
            kVar.f23060a.put(uuid, new Pair<>(new ArrayList(arrayList), new WeakReference(addIllustsFromIllustViewPagerCallback)));
            intent.putExtra("ILLUSTS_POSITION", i);
            intent.putExtra("LIST_HASH", uuid);
            intent.putExtra("NEXT_URL", str);
            intent.putExtra("VIA", componentVia);
            intent.putExtra("PREVIOUS_SCREEN", cVar);
            return intent;
        }
    }

    /* renamed from: j1 */
    public static final Intent m4823j1(Context context, List<? extends PixivIllust> list, int i, AddIllustsFromIllustViewPagerCallback addIllustsFromIllustViewPagerCallback, String str, ComponentVia componentVia) {
        C4012a aVar = f18371r0;
        MutabilityOwnership.m3745m(context, "context");
        MutabilityOwnership.m3745m(list, "illusts");
        return aVar.m4821a(context, list, i, addIllustsFromIllustViewPagerCallback, str, null, null);
    }

    /* renamed from: k1 */
    public static final Intent m4822k1(Context context, List<? extends PixivIllust> list, int i) {
        C4012a aVar = f18371r0;
        MutabilityOwnership.m3745m(context, "context");
        MutabilityOwnership.m3745m(list, "illusts");
        return aVar.m4821a(context, list, i, null, null, null, null);
    }

    @Override // p014ae.AbstractActivityC0101k, androidx.viewpager.widget.ViewPager.AbstractC0898i
    /* renamed from: Y */
    public void mo943Y(int i) {
        super.mo943Y(i);
        if ((m12139h1().mo938c() - i) + 1 < 5) {
            String str = this.f18373n0;
            if (!(str == null || str.length() == 0) && !this.f18374o0) {
                this.f18374o0 = true;
                m12140g1().mo82c(PixivRequest.m5813d(this.f18373n0).m986o(AndroidSchedulers.m334a()).m984q(new C0185y(this, 1), new C0135p4(this, 0), Functions.f5386c, Functions.f5387d));
            }
        }
        C5417y yVar = this.f434g0;
        if (yVar != null) {
            yVar.m8490b(3);
        }
        C5410r rVar = this.f435h0;
        if (rVar != null) {
            rVar.m8490b(3);
        }
        C3114c.m6284b().m6280f(new IllustDetailPageChangeEvent());
        PixivIllust p = m12139h1().m10334p(i);
        MutabilityOwnership.m3746l(p, "illustDetailPagerAdapter.getIllust(position)");
        this.f18757A.m6526d(new ImpDetailEvent.C3339a(p.f19079id, this.f18375p0, this.f18376q0));
        GoogleNg resolveGoogleNg = m12139h1().m10334p(i).resolveGoogleNg();
        MutabilityOwnership.m3746l(resolveGoogleNg, "illustDetailPagerAdapter…sition).resolveGoogleNg()");
        m12145X0(resolveGoogleNg);
        this.f18376q0 = AnalyticsScreenName.ILLUST_DETAIL;
    }

    @Override // p014ae.AbstractActivityC0101k
    /* renamed from: i1 */
    public void mo4819i1() {
        this.f18373n0 = getIntent().getStringExtra("NEXT_URL");
        this.f433f0 = getIntent().getStringExtra("LIST_HASH");
        this.f18375p0 = (ComponentVia) getIntent().getParcelableExtra("VIA");
        this.f18376q0 = (AnalyticsScreenName) getIntent().getSerializableExtra("PREVIOUS_SCREEN");
        int intExtra = getIntent().getIntExtra("ILLUSTS_POSITION", -1);
        ItemPagerListManager kVar = ItemPagerListManager.f23059b;
        Pair<ArrayList<PixivIllust>, WeakReference<AddIllustsFromIllustViewPagerCallback>> pair = kVar.f23060a.get(this.f433f0);
        if (pair == null) {
            Intent intent = new Intent(this, RoutingActivity.class);
            intent.setFlags(268468224);
            startActivity(intent);
            return;
        }
        Object obj = pair.first;
        MutabilityOwnership.m3746l(obj, "listAndCallback.first");
        this.f18372m0 = (WeakReference) pair.second;
        IllustPagerAdapter h1 = m12139h1();
        h1.f4929j.addAll((List) obj);
        h1.m7542h();
        m12142e1().f21872u.setCurrentItem(intExtra);
        if (intExtra == 0) {
            mo943Y(intExtra);
        }
    }
}
